const app=getApp()

Page({
  data: {
    username:'',
    password:'',
    checked: false,
    checked2: false,
   
  },
  onChange2(event) {
    this.setData({
      checked2: event.detail,
    });
  },

  
    
  
  login(){
    let url=app.globalData.URL+'/users/login';
    let data={
         username:this.data.username,
         password:this.data.password
    };
    
   
    if(this.data.checked2 == false){
        wx.showToast({
          title: '请先阅读勾选用户协议',
        })
    }else{
        
    
    
    
    console.log(url)
     app.wxRequest('GET',url,data,(res)=>{
        if(res.statusCode==200){
            getApp().globalData.user=res.data
            wx.redirectTo({
              url: '/pages/index/index',
            })
            
           }else if(res.statusCode==500){
               wx.showToast({
                 title: '账号或密码错误',
               })
           }
           else{
             reject(res.data.message || '系统出错了')
           }
    },(err)=>{
        console.log(err.errMsg);
    });
   
    }
    
  },
  onForgotPassword(){
    wx.navigateTo({
      url: '/pages/findPassword/findPassword?num=2',
    })
  },
  zczh(){
    wx.navigateTo({
        url: '/pages/findPassword/findPassword?num=1',
      })
    
  },
  onChangeUsername(event) {
    this.setData({
      username: event.detail
    });
  },
  onChangePassword(event) {
    this.setData({
      password: event.detail
    });
  },
  onChangeChecked(event) {
    this.setData({
      checked: event.detail
    });
  },
  onLogin() {
    if (!this.data.username || !this.data.password) {
      wx.showToast({
        title: '请输入用户名和密码',
        icon: 'none'
      });
      return;
    }
    // 在这里添加登录逻辑
    wx.showToast({
      title: '登录成功',
      icon: 'success'
    });
  }
});
